﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.IO;

namespace WikcLib.Data
{
    public class TextHelper
    {
        public static void WriteText(string strMsg, string strFileName)
        { 
            try
            {
                StreamWriter sw = new StreamWriter(strFileName);
                sw.WriteLine(strMsg);
                sw.Close();
            }
            catch (Exception)
            {
                throw;
            } 
        }

        /// <summary>
        /// 读取txt内容
        /// </summary>
        /// <param name="strFileName"></param>
        /// <returns></returns>
        public static string ReadText(string strFileName)
        {

            try
            {
                if (!File.Exists(strFileName))
                {
                    StreamWriter sw = new StreamWriter(strFileName);
                    sw.WriteLine("");
                    sw.Close();
                }
                string[] list = File.ReadAllLines(strFileName);
                StringBuilder sb = new StringBuilder();
              
                foreach (var item in list)
                {
                    sb.Append(item.ToString());
                }

                return sb.ToString();
            }
            catch (Exception)
            { 
                throw;
            } 
        }
    }
}
